import {createAsyncThunk, createSlice} from "@reduxjs/toolkit";
import {reqArticleIntro} from "../../api/frontDesk/frontDeskApi";


//获取到文章列表基础信息
export const getArticleIntro = createAsyncThunk(
    'article/getArticleIntroStatus',
    async (state, action) => {
        const data = await reqArticleIntro()
        // console.log(data)
        const {articleList} = data
        // console.log(articleList)
        return Array.from(articleList)
    }
)


const articleSlice = createSlice({
    name: 'article',
    initialState: {
        homeArticleList: [],
        likeIds: {}
    },
    reducers: {
        updateArticleList(state, action) {
            state.homeArticleList = action.payload
        },
    },
    extraReducers: (builder) => {
        builder.addCase(getArticleIntro.fulfilled, (state, action) => {
            state.homeArticleList = action.payload
        })
    }
})

export const {updateArticleList,getLikeIds} = articleSlice.actions

export const {reducer: articleReducer} = articleSlice